#ifndef OBJECT_H
#define OBJECT_H

#include "objReader.h"

#include <QCAR/QCAR.h>
#include <QCAR/Matrices.h>
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <iostream>
#include <fstream>
#include <string>

#include "Vehicle.h"

#include "SampleUtils.h"
#include "SampleMath.h"
#include "Texture.h"

using namespace std;

struct color
{
	float red;
	float green;
	float blue;
	float alpha;
};

class Object
{
public:
	Object ( unsigned int, float,float,float,float,float,float,float,color,int,bool );
	Object ( unsigned int shaderProgramID = 0.0 , float size = 1.0, float x = 0.0,float y = 0.0, float z = 0.0,
			 float gx = 0.0, float gy = 0.0, float gz = 0.0,
			 float red = 0.0, float green = 0.0, float blue = 1.0, float alpha = 0.0,
			 int textureIndex = 1,
			 bool visible  = true );
	inline float	getX	 ( ) { return _vehicle.getPos().x; }
	inline float	getY     ( ) { return _vehicle.getPos().y; }
	inline float	getZ     ( ) { return _z;  }
	inline float	getGX    ( ) { return _gx; }
	inline float	getGY    ( ) { return _gy; }
	inline float	getGZ    ( ) { return _gz; }
	inline float	getSize  ( ) { return _gz; }
	inline bool		isVisible( ) { return _visible; }
	inline float	getTexture() {return _textureIndex; }

	inline void		setPos  ( float x, float y  ) { _vehicle.setPos( Vector2D( x, y ) );   }
	inline void		setZ    ( float z  )    { _z = z;   }
	inline void		setGX   ( float gx )    { _gx = gx; }
	inline void		setGY   ( float gy )    { _gy = gy; }
	inline void		setGZ   ( float gz )    { _gz = gz; }
	inline void		setSize ( float size )  { _size = size; }
	inline void		visible ( bool visible ){ _visible = visible; }
	inline void		setColor( color c )     { _colors = c; }
	inline void		setColor( float r, float g, float b, float a ) {_colors.red = r;_colors.green = g;_colors.blue = b; _colors.alpha = a;}
	inline void		setTexture( int index )     { _textureIndex = index; }
	void			setShaderProgramID( unsigned int );
	void	draw ( QCAR::Matrix44F*, QCAR::Matrix44F*, Texture** );
	Vehicle _vehicle;
protected:
	float	_size;
	float	_z;
	float	_gx;
	float	_gy;
	float	_gz;
	color	_colors;
	bool	_visible;
	int		_textureIndex;
	unsigned int _shaderProgramID;
	GLint _vertexHandle;
	GLint _normalHandle;
	GLint _textureCoordHandle;
	GLint _mvpMatrixHandle;
	virtual void	drawObject( QCAR::Matrix44F*, Texture** );
};

class TeaPot : public Object
{
public:
	TeaPot( unsigned int, float,float,float,float,float,float,float,color,int,bool );
	TeaPot( unsigned int shaderProgramID = 0, float size = 1.0, float x = 0.0,float y = 0.0, float z = 0.0,
			 float gx = 0.0, float gy = 0.0, float gz = 0.0,
			 float red = 0.0, float green = 0.0, float blue = 1.0, float alpha = 0.0,
			 int textureIndex = 1,
			 bool visible  = true );
private:
	void drawObject( QCAR::Matrix44F*, Texture** );
};

class ObjObject : public Object
{
public:
	ObjObject( unsigned int, float,float,float,float,float,float,float,color,int,bool );
	ObjObject( unsigned int shaderProgramID = 0, float size = 1.0, float x = 0.0,float y = 0.0, float z = 0.0,
			 float gx = 0.0, float gy = 0.0, float gz = 0.0,
			 float red = 0.0, float green = 0.0, float blue = 1.0, float alpha = 0.0,
			 int textureIndex = 1,
			 bool visible  = true );
	bool loadObjObject (string objectName);
private:
	obj3d * obj;
	void drawObject( QCAR::Matrix44F*, Texture** );
};

#endif
